package org.huang.util;

import java.io.Serializable;
import java.util.Objects;

/**
 * @author hdu_huang
 * @since 2024/8/26 11:22
 * desc  不变二元组, key,value都可以为null
 */
public record Pair<K, V>(K key, V value) implements Serializable {

    public static <K, V> Pair<K, V> of(K key, V value) {
        return new Pair<>(key, value);
    }

    @Override
    public String toString() {
        return key + "=" + value;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o instanceof Pair<?, ?> pair) {
            if (!Objects.equals(key, pair.key)) return false;
            return Objects.equals(value, pair.value);
        }
        return false;
    }
}